#!/bin/bash
set -e -o pipefail

NOW_UNIX_TIME=`date +%s`000
if [ -d "${SS_PATH}" ]; then 

  PROC_PATH="/opt/fonsview/NE/ss/data/proc"
  if [ -d "$PROC_PATH" ];then
    NodeID=`fgrep "*" ${PROC_PATH}/mng/nodes | fgrep -v "*:"|awk -F "*| " '{print $2}'|sed 's/-//g'`
    current=`fgrep "current_online_sessions" /opt/fonsview/NE/ss/data/proc/sts/${NodeID}| awk -F '=' '{print $2}'`
    vod=`grep "^vod_online_sessions" /opt/fonsview/NE/ss/data/proc/sts/${NodeID}| awk -F '=' '{print $2}'`
    tvod=`fgrep "tvod_online_sessions" /opt/fonsview/NE/ss/data/proc/sts/${NodeID}| awk -F '=' '{print $2}'`
    live=`fgrep "live_online_sessions" /opt/fonsview/NE/ss/data/proc/sts/${NodeID}| awk -F '=' '{print $2}'`
    tstv=`fgrep "tstv_online_sessions" /opt/fonsview/NE/ss/data/proc/sts/${NodeID}| awk -F '=' '{print $2}'`

    echo "# HELP node_ss_nodes_sessions exporter ss_online_sessions"
    echo "# TYPE node_ss_nodes_sessions gauge"
    echo "node_ss_nodes_sessions{online=\"current\"} ${current}"
    echo "node_ss_nodes_sessions{online=\"vod\"} ${vod}"
    echo "node_ss_nodes_sessions{online=\"tvod\"} ${tvod}"
    echo "node_ss_nodes_sessions{online=\"live\"} ${live}"
    echo "node_ss_nodes_sessions{online=\"tstv\"} ${tstv}"

  fi
fi
